<template>
  <el-container class="template-view panel-block">
    <el-main>
      <el-table class="sa-table" :data="template.list" stripe>
        <el-table-column prop="id" label="ID" min-width="80" />
        <el-table-column prop="name" label="名称" min-width="180">
          <template #default="scope">
            <div class="sa-line-1">
              {{ scope.row.name }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="type_text" label="类型" min-width="80" />
        <el-table-column prop="name" label="名称" min-width="100" fixed="right">
          <template #default="scope">
            <el-button class="is-link" type="primary" @click="onSelect(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
  </el-container>
</template>

<script>
  export default {
    name: 'TemplateSelect',
  };
</script>

<script setup>
  import { onMounted, reactive } from 'vue';
  import { api } from '../decorate.service';

  const emit = defineEmits(['modalCallBack']);

  const template = reactive({
    loading: false,
    list: [],
  });

  async function getData() {
    template.loading = true;
    const { data } = await api.template.select();
    template.list = data;
    template.loading = false;
  }

  function onSelect(row) {
    emit('modalCallBack', { event: 'confirm', data: row });
  }

  onMounted(() => {
    getData();
  });
</script>
